package com.lzb.permanentcalendar.adapter;

import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.permanentcalendar.R;
import com.lzb.permanentcalendar.basic.ProviderMultiAdapter;
import com.othershe.calendarview.bean.JrBean;

public class FestivalAdapter extends ProviderMultiAdapter<JrBean> {

    public FestivalAdapter() {
        addItemProvider(new FestivalProvider());
    }

    private class FestivalProvider extends BaseItemProvider<JrBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_festival;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, JrBean bean) {
            baseViewHolder.setText(R.id.tvFestivalItemDay, bean.getDay() + "");
            baseViewHolder.setText(R.id.tvFestivalItemMonth, bean.getMo() + getContext().getString(R.string.month));
            baseViewHolder.setText(R.id.tvFestivalItemName, bean.getJrName());
            baseViewHolder.setText(R.id.tvFestivalItemDate, bean.getYear() + "年" + bean.getMo() + "月" + bean.getDay() + "日");
            if (bean.getNum() == 0) {
                baseViewHolder.getView(R.id.tvFestivalItemCountdown).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.tvFestivalItemDayText).setVisibility(View.GONE);
                baseViewHolder.setText(R.id.tvFestivalItemNum, getContext().getString(R.string.today));
            } else {
                baseViewHolder.getView(R.id.tvFestivalItemCountdown).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.tvFestivalItemDayText).setVisibility(View.VISIBLE);
                if (bean.getNum() > 0) {
                    baseViewHolder.setText(R.id.tvFestivalItemCountdown,getContext().getString(R.string.countdown));
                    baseViewHolder.setText(R.id.tvFestivalItemNum, " " + bean.getNum() + " ");
                }else {
                    baseViewHolder.setText(R.id.tvFestivalItemCountdown,getContext().getString(R.string.already));
                    baseViewHolder.setText(R.id.tvFestivalItemNum, " " + Math.abs(bean.getNum()) + " ");
                }
            }
        }
    }

}
